package com.longge;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @创建人 xinglongge
 * @创建时间 2021/9/26
 * @描述
 */
public class EraseOverlapIntervals {

    public int eraseOverlapIntervals(int[][] intervals) {
        if (intervals.length == 0) return 0;
        Arrays.sort(intervals, Comparator.comparingInt(o -> o[1]));

        int count = 1;
        int end = intervals[0][1];
        for (int i = 1; i < intervals.length; i++) {
            int start = intervals[i][0];
            if (start >= end) {
                count++;
                end = intervals[i][1];
            }
        }
        return  count;
    }

}
